<template>
    <div>
        <Button type="primary" @click="exportData"><Icon type="ios-download-outline"></Icon>导出数据</Button>
        <Button type="success" icon="ios-contrast" style="margin-left: 20px" @click="yjdb()" :disabled="dis">一键对比</Button>
        <Button type="error" icon="ios-trash-outline" style="margin-left: 20px" @click="deleted()">一键清空</Button>
        <Table border :columns="columns12" :data="data6" style="margin-top: 20px" ref="table" :loading="loading">
        </Table>
    </div>
</template>

<script>
import { dczb, insertAll, deleteAll, deletechaiAll } from '@/api/user'
export default {
  data () {
    return {
      loading: true,
      dis: true,
      columns12: [
        {
          title: '交易流水号',
          key: 'batch_number',
          align: 'center'
          // width: '100'
        },
        {
          title: '金额(元)',
          key: 'money',
          align: 'center'
          // width: '80'
        },
        {
          title: '交易类型',
          key: 'transaction_type',
          align: 'center'
          // width: '100'
        },
        {
          title: '交易状态',
          key: 'transaction_status',
          align: 'center'
          // width: '100'
        },
        {
          title: '卡号/客户编号',
          key: 'card_num',
          align: 'center'
          // width: '100'
        },
        {
          title: '客户名称',
          key: 'name',
          align: 'center'
          // width: '100'
        },
        {
          title: '商品种类',
          key: 'type',
          align: 'center'
          // width: '100'
        },
        {
          title: '油量(升)',
          key: 'fuel',
          align: 'center'
          // width: '80'
        },
        {
          title: '车辆牌照',
          key: 'plat_number',
          align: 'center'
          // width: '100'
        },
        {
          title: '长车牌照',
          key: 'plat_number_long',
          align: 'center'
          // width: '100'
        },
        // {
        //   title: '多次加油的次数',
        //   key: 'count_num',
        //   align: 'center'
        // },
        {
          title: '受理机构',
          key: 'acceptance_organization',
          align: 'center'
          // width: '100'
        },
        {
          title: '业务日期',
          key: 'business_time',
          align: 'center'
          // width: '100'
        },
        {
          title: '交易时间',
          key: 'transaction_time',
          align: 'center'
          // width: '100'
        },
        {
          title: '石油公司',
          key: 'oil_companies',
          align: 'center'
          // width: '100'
        },
        {
          title: '被监督单位',
          key: 'company',
          align: 'center',
          width: '80'
        },
        {
          title: '问题类型',
          key: 'problemName',
          align: 'center',
          width: '80'
        }

      ],
      data6: []
      // headerField: [
      //   { title: '交易流水号', field: 'batch_number', minWidth: 300 },
      //   { title: '金额', field: 'money', minWidth: 300 }
      // ]
    }
  },

  props: {

  },

  components: {

  },

  computed: {

  },

  methods: {
    async init (data) {
      dczb().then(ret => {
        console.log(ret, 'ret!!!!!!!!')
        if (ret.data.data.length === 0) {
          this.$Notice.error({
            title: '请先一键对比'
          })
          this.loading = false
          this.dis = false
        } else {
          this.data6 = ret.data.data
          this.loading = false
          this.dis = true
        }
      })
    },
    exportData () {
      for (let i = 0; i < this.data6.length; i++) {
        if (this.data6[i].batch_number) {
          this.data6[i].batch_number = '\t' + this.data6[i].batch_number
        }
        if (this.data6[i].card_num) {
          this.data6[i].card_num = '\t' + this.data6[i].card_num
        }
      }
      this.$refs.table.exportCsv({
        filename: '导出文件',
        columns: this.columns12,
        data: this.data6
      })
    },
    yjdb () {
      insertAll().then(ret => {
        if (ret.data.data === 'success') {
          this.$Message.success('对比成功')
          this.loading = true
          this.init()
          // dczb().then(ret => {
          //   console.log(ret, 'ret!!!!!!!!')
          //   if (ret.data.data !== '') {
          //     this.data6 = ret.data.data
          //     this.loading = false
          //   } else {
          //     this.$Message.error('请点击一键对比')
          //   }
          // })
        } else {
          this.$Message.error('对比失败')
        }
        console.log(ret, 'ret!!!!!!!!!')
      })
    },
    deleted () {
      this.$Modal.confirm({
        title: '确认要全部删除吗?',
        content: '<p>内容一旦删除将无法恢复</p>',
        loading: true,
        onOk: async () => {
          deleteAll().then(ret => {
            this.data6 = ret.data.data.results
            // console.log()
          })
          deletechaiAll().then(ret => {
            this.data6 = ret.data.data.results
          })
          setTimeout(() => {
            this.$Modal.remove()
            this.$Message.success('删除成功')
          }, 1000)
          this.dis = false
        }
      })
    }
  },

  watch: {

  },

  mounted () {
    this.init()
  }

}
</script>

<style scoped>
    .pg{
        margin-top: 20px;
    }
</style>
